package org.example.book.facade;

import org.example.book.factory.PayContextFactory;
import org.example.book.state.pojo.Order;
import org.example.book.strategy.AlipayStrategy;
import org.example.book.strategy.WechatStrategy;
import org.example.book.strategy.context.PayContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PayFacade {

    @Autowired
    private PayContextFactory contextFactory;

//    public String pay(Order order, Integer payType) {
//        switch (payType) {
//            case 1:
//                AlipayStrategy alipayStrategy = new AlipayStrategy();
//                PayContext payContext = new PayContext(alipayStrategy);
//                return payContext.execute(order);
//            case 2:
//                WechatStrategy wechatStrategy = new WechatStrategy();
//                PayContext payContext1 = new PayContext(wechatStrategy);
//                return payContext1.execute(order);
//            default:
//                throw new UnsupportedOperationException("err paytype");
//        }
//    }

    public String pay(Order order, Integer payType) {
        PayContext context = contextFactory.getContext(payType);
        return context.execute(order);
    }
}
